package org.lt.resume.util.common.tools;

import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import javax.servlet.ServletContext;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class FileDownloadController extends ActionSupport{

	/****/
	private static final long serialVersionUID = -2593295140062139005L;

	// 初始的通过param指定的文件名属性
	private String fileName;
	InputStream inputSream;
	// 指定的下载路径
	private String inputPath;

	public InputStream getInputStream() throws Exception{

//		return new ByteArrayInputStream("hello".getBytes());
        ServletContext sc = ServletActionContext.getServletContext();
        String realpath = sc.getRealPath("/upload");
        String path = realpath + "\\" + fileName;
        System.out.println("<<<" + this.fileName);
        System.out.println(">>>" + path);
		inputSream = ServletActionContext.getServletContext().getResourceAsStream(path);
		if (inputSream == null){
			System.out.println("===========fuck-===================");
		}
        return ServletActionContext.getServletContext().getResourceAsStream("/upload/系统.doc");
		
//		inputSream = ServletActionContext.getServletContext().getResourceAsStream(inputPath);
//		if (inputSream == null){
//			System.out.println("===========fuck-===================");
//		}
//		return ServletActionContext.getServletContext().getResourceAsStream(inputPath);

	}

	@Override
	public String execute() throws Exception {

		return SUCCESS;
	}
//
//	public String getInputPath() {
//		return inputPath;
//	}

	public void setInputPath(String inputPath) {
		this.inputPath = inputPath;
	}

//	public String getFileName() {
//		return fileName;
//	}
//
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getDownloadFileName() {
		String downFileName = fileName;
		try {
			downFileName = new String(downFileName.getBytes(),"ISO8859-1");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return downFileName;
	}
	
	
}
